﻿using UnityEngine;
using System.Collections;

public class Reference : MonoBehaviour {

	// Use this for initialization
	void Awake () 
	{
		m_playerProperty = GameObject.FindGameObjectWithTag ("Player").GetComponent<HumanProperty> ();
		m_property = GetComponent<HumanProperty> ();
	}

	void Start()
	{
		m_property.BodyWidth = m_playerProperty.BodyWidth;
		m_property.BodyHeight = m_playerProperty.BodyHeight;
		m_property.HeadWidth = m_playerProperty.HeadWidth;
		m_property.HeadHeight = m_playerProperty.HeadHeight;
		m_property.HandLength = m_playerProperty.HandLength;
		m_property.LegLength = m_playerProperty.LegLength;

		for (int i = 0; i < 8; i += 3) 
		{
			int rand = Random.Range(1, 3);
			Debug.Log(rand);
			m_property.Combine(GameObject.Find("Human" + (i + rand).ToString()).GetComponent<Spouse>().m_property);
		}

		m_property.UpdateShow ();
	}
	
	public float Compare()
	{
		float f1 =  Mathf.Abs((float)m_playerProperty.BodyWidth - (float)m_property.BodyWidth) / ((float)m_property.BodyWidth);
		float f2 =  Mathf.Abs((float)m_playerProperty.BodyHeight - (float)m_property.BodyHeight) / ((float)m_property.BodyHeight);
		float f3 =  Mathf.Abs((float)m_playerProperty.HeadWidth - (float)m_property.HeadWidth) / ((float)m_property.HeadWidth);
		float f4 =  Mathf.Abs((float)m_playerProperty.HeadHeight - (float)m_property.HeadHeight) / ((float)m_property.HeadHeight);
		float f5 =  Mathf.Abs((float)m_playerProperty.HandLength - (float)m_property.HandLength) / ((float)m_property.HandLength);
		float f6 =  Mathf.Abs((float)m_playerProperty.LegLength - (float)m_property.LegLength) / ((float)m_property.LegLength);

		float weightedAverage = f1 * 0.125f + f2 * 0.125f + f3 * 0.125f + f4 * 0.125f + f5 * 0.25f + f6 * 0.25f;
		return 1.0f - weightedAverage;
	}

	private HumanProperty m_playerProperty;
	private HumanProperty m_property;
}
